package com.iot.ammeter.controller.other;

import com.iot.ammeter.anno.LogAnnotation;
import com.iot.ammeter.responseResult.ResponseResult;
import com.iot.ammeter.service.other.UploadImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: UploadImagesController
 * @Author: Basil
 * @Date: 2021/10/9 下午2:35
 * @Version: 1.0
 **/
@RestController
@Api(tags = "上传图片")
@RequestMapping("/api/image")
public class UploadImagesController {

    private final UploadImageService uploadImageService;

    public UploadImagesController(UploadImageService uploadImageService) {
        this.uploadImageService = uploadImageService;
    }

    /**
     * 上传图片
     *
     * @param img  图片
     * @param type 1为logo 2为头像
     * @return 返回图片上传后的路径
     */
    @ApiOperation("上传图片")
    @LogAnnotation(module = "uploadImage", operator = "上传图片")
    @PostMapping("/{type}")
    public ResponseResult uploadImage(@RequestParam("img") MultipartFile img, @PathVariable String type) {
        return ResponseResult.SUCCESS(uploadImageService.uploadImage(img, type));
    }
}
